<template>
	<view class="wrap">
		<view class="search">
			<image src="@/static/search.png"></image>
			<input type="text" placeholder="搜索姓名" @input="debounce('fetchData',1000)" v-model="studentName" />
		</view>
		<view v-if="isInit" v-cloak>
			<view class="menu">
				<view class="borderBottom column" v-for="(item, index) in menuInfo.list" :key="index" :class="menuInfo.base.class">
					<navigator :url="item.url" :class="item.class">
						<text v-text="`${item[ele]}的家长`" v-for="(ele, index) in menuInfo.base.menuProp" :key="index" v-if="isParent"></text>
						<text v-text="item[ele]" v-for="(ele, index) in menuInfo.base.menuProp" :key="index" v-else></text>
						<icon class="iconfont iconarrow-right-copy-copy next"></icon>
					</navigator>
				</view>
			</view>
		</view>
		<!-- <view class="letters">
			<text v-for="item in letterData" v-text="item" :key="item"></text>
		</view> -->
	</view>
</template>

<script>
	import {
		mapActions
	} from 'vuex'
	export default {
		data() {
			return {
				departmentId: '',
				studentName:"",
				// letterData:['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'],
				menuInfo: {
					base: {
						menuProp: ['name']
					},
					list: []
				},
				isInit: false,
				options: "",
				isParent:"",
				timeout:null
			}
		},
		onShow() {
			let pageOptions = this.getPageOptions();
			this.classCode = pageOptions.classCode
			this.isParent = pageOptions.isParent||''
			this.fetchData()
		},
		methods: {
			//搜索防抖
			 debounce(func, wait) {
			        let context = this
			        if (this.timeout) clearTimeout(this.timeout)
			        this.timeout = setTimeout(() => {
			            context[func]()
			        }, wait)
			},
			async fetchData() {
				let resp = await this.$http.post({
					url: `/stu/addressList/studentCommonPage`,
					data: {
						classCode: this.classCode,
						name:this.studentName
					}
				});
				this.menuInfo.list = resp.result.records.map(item => {
					return {
						id: item.id,
						name: item.name,
						url: `detail?data=${JSON.stringify(item)}&isParent=${this.isParent}`,
					}
				})
				this.isInit = true
			}
		}
	}
</script>

<style lang="scss" scoped>
	// .letters {
	// 	position: fixed;
	// 	top: 0px;
	// 	right: 0;
	// 	width: 30px;
	// 	height: 100%;
	// 	background: #eee;
	// 	z-index: 9999;
	// 	display: flex;
	// 	flex-flow: column;
	// }
	// .letters text {
	// 	display: block;
	// 	font-size: 14px;
	// 	color: #666;
	// 	text-align: center;
	// 	flex: 1;
	// }
	.search {
		width: 650upx;
		margin: 0 auto 20upx auto;
		border: 1upx solid #ddd;
		height: 60upx;
		border-radius: 30upx;
		position: relative;
	
		image {
			width: 50upx;
			height: 50upx;
			position: absolute;
			top: 5upx;
			left: 10upx;
		}
	
		input {
			width: 590upx;
			height: 50upx;
			position: absolute;
			left: 60upx;
			top: 5upx;
			color: #999;
			font-size: 28upx;
		}
	
		.input-placeholder {
			color: #999;
			font-size: 28upx;
		}
	}
	
	.menu {
		padding: 0 50upx 120upx 50upx;
	
		.column {
			display: flex;
			align-items: center;
	
			.choose {
				width: 30upx;
				height: 30upx;
				border-radius: 50%;
				background: #fff;
				margin: 0 10upx;
				font-size: 0;
				border: 1upx solid #ccc;
			}
	
			.chooseActive {
				width: 30upx;
				height: 30upx;
				border-radius: 50%;
				font-size: 22upx;
				background: #3ED392;
				color: #fff;
				margin: 0 10upx;
				line-height: 30upx;
				text-align: center;
			}
	
		}
	
		navigator {
			flex: 0 1 100%;
			height: 80upx;
			line-height: 80upx;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
	
		.tit {
			display: flex;
			justify-content: space-between;
	
			text {
				font-size: 28upx;
				line-height: 100upx;
				font-weight: 600;
			}
		}
	
		.next {
			margin-left: auto;
			float: right;
		}
	}
	
	page {
		min-height: 100%;
	
		.wrap {
			min-height: 100%;
			padding-top: 20upx;
		}
	
		.submitButtonActive {
			position: fixed;
			bottom: 20upx;
			left: 50%;
			transform: translateX(-50%);
		}
	}
</style>
